package cc.rengu.redp.bizimpl.csmc.controller;


import cc.rengu.redp.bizimpl.csmc.service.IReconSceneMonitorService;
import cc.rengu.redp.bizimpl.csmc.vo.ReconSceneMonitorVO;
import cc.rengu.redp.common.annotation.Log;
import cc.rengu.redp.common.controller.BaseController;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.Map;

/**
 * @author guohaocong
 */
@Slf4j
@Api(tags = "统一对账管理：对账场景监控管理")
@RestController
@RequestMapping("/admin/csmc/recon-scene-monitor")
public class ReconSceneMonitorController  extends BaseController {

    @Autowired
    private IReconSceneMonitorService reconSceneMonitorService;

    @Log("分页")
    @GetMapping
    public Map<String ,Object> getPageList(QueryRequest request, ReconSceneMonitorVO reconSceneMonitorVO) {
        return getDataTable(reconSceneMonitorService.findPage(request,reconSceneMonitorVO));
    }

    @Log("修改")
    @PutMapping
    //    @RequiresPermissions("reconSceneMonitor:update")
    public void editReconSceneMonitor(ReconSceneMonitorVO reconSceneMonitorVO) throws RedpException {
        try {
            reconSceneMonitorService.editReconSceneMonitor(reconSceneMonitorVO);
        } catch (Exception e) {
            String message = e.getMessage();
            log.error(message, e);
            throw new RedpException(message);
        }
    }

    @Log("新增")
    @PostMapping
    public void saveReconSceneMonitor(ReconSceneMonitorVO reconSceneMonitorVO) throws RedpException {
        try {
            reconSceneMonitorService.saveReconSceneMonitor(reconSceneMonitorVO);
        } catch (Exception e) {
            String message = e.getMessage();
            log.error(message, e);
            throw new RedpException(message);
        }
    }

    @Log("删除")
    @DeleteMapping("/{reconSceneMonitorIds}")
    public void deleteReconSceneMonitor(@NotBlank(message = "{required}") @PathVariable String reconSceneMonitorIds) throws RedpException {
        try {
            String[] ids = reconSceneMonitorIds.split(StringPool.COMMA);
            this.reconSceneMonitorService.deleteReconSceneMonitor(ids);
        } catch (Exception e) {
            String message = "删除失败";
            log.error(message, e);
            throw new RedpException(message);
        }

    }
}
